package com.game.server.message.proto.execute;

import com.comm.ISession;
import com.game.majiang.logic.LogicClient;
import com.game.majiang.logic.LogicServer;
import com.game.majiang.logic.chexuan.ChexuanPlayer;
import com.game.server.message.proto.in.AbstractPlayerOperateCuopaiReq;
import com.game.server.message.proto.out.PlayerOperateCuopaiRsp;
import com.game.server.system.AbstractPlayer;
import com.game.server.system.AbstractTable;

public class PlayerOperateCuopaiReq extends AbstractPlayerOperateCuopaiReq {

    @Override
    public void Execute(ISession session) {
        LogicClient client = (LogicClient) LogicServer.getInstance().getClient(session.getId());
        if (client != null&&client.checkClick(msgcode)) {
            AbstractTable abTable = client.getTable();
            PlayerOperateCuopaiRsp rsp = new PlayerOperateCuopaiRsp();
            rsp.setIsok(1);
            rsp.setType(type);
            if(abTable != null) {
            	AbstractPlayer abPlayer = abTable.getPlayer(client.getUserId());
            	if(abPlayer != null) {
            		ChexuanPlayer player = (ChexuanPlayer) abPlayer;
            		player.setCuopaiBool(this.type.intValue() == 1);
            		rsp.setIsok(0);
            		rsp.setUid(client.getUserId());
            	}
            }
            if(rsp.getIsok().intValue() == 0) {
            	abTable.BroadCast(rsp, 2);
            } else {
            	client.Send(rsp);
            }
            
        }
    }

}
